import { request } from '@/config/request'

export interface sendCodeType {
    phone: number | string
}

export function sendCode(data: sendCodeType) {
    return request.http({
        url: '/api/t.sms/sendCode',
        data
    })
}

// 上传图片
export function uploadFile(file: any) {
    let url = ''
    // #ifdef APP-PLUS
    url = import.meta.env.VITE_APP_BASE_URL
    // #endif
    // #ifdef H5
    url = import.meta.env.VITE_APP_BASE_PRE
    // #endif
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: `${url}/api/resources/upload`,
            filePath: file,
            name: 'file',
            success: (res) => {
                resolve(JSON.parse(res.data))
            },
            fail: (res) => {
                reject(res)
            }
        })
    })
}

// 直采支付
export function voucherPay(data: { id: number }) {
    return request.http({
        url: '/api/d.pickGiftBag/buy',
        data
    })
}
